﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Text;

namespace Marmat.Common.Http
{
    public class LogMessage
    {
        /// <summary>
        /// 请求地址
        /// </summary>
        public HttpWebRequest Request { get; set; }

        /// <summary>
        /// 请求内容的文本描述。
        /// </summary>
        public string RequestString { get; set; }

        ///// <summary>
        ///// 返回内容的文本描述。
        ///// </summary>
        //public string ResponseString { get; set; }

        /// <summary>
        /// 将日志信息格式化成指定的输出文本。
        /// </summary>
        /// <param name="spaceCount"></param>
        /// <returns></returns>
        public string ToIndentedString(int spaceCount = 4)
        {
            int level = 0;
            StringBuilder builder = new();
            builder.AppendLine("");
            builder.AppendLine("常规");
            level++;
            string spaceString = new string(' ', level * spaceCount);
            spaceString = "";

            builder.AppendLine($"{spaceString}请求 URL：{this.Request.RequestUri.OriginalString}");
            builder.AppendLine($"{spaceString}请求方法：{this.Request.Method}");

            builder.AppendLine("");
            builder.AppendLine("请求标头");
            builder.AppendLine($"{spaceString}{this.Request.Headers.ToString().Trim()}");

            builder.AppendLine("");
            builder.AppendLine("请求内容");
            builder.AppendLine($"{spaceString}{this.RequestString}");

            return builder.ToString();
        }
    }
}
